package com.xd.shading.config.sharding;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;

import java.util.Collection;

@Slf4j
public class DbStandardShardingAlgorithm implements StandardShardingAlgorithm<String> {
    @Override
    public String getType() {
        log.info("进入DbStandardShardingAlgorithm的getType方法");
        return "STANDARD";
    }

    @Override
    public void init() {
        log.info("进入DbStandardShardingAlgorithm的init方法");
    }

    @Override
    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<String> shardingValue) {
            return "db1" ;

    }

    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames,
                                         RangeShardingValue<String> shardingValue) {
        log.info("进入DbStandardShardingAlgorithm的doSharding2方法：" + availableTargetNames);
        log.info("进入DbStandardShardingAlgorithm的doSharding2方法：" + shardingValue);
        return availableTargetNames;
    }
}
